(function(KKBus){

    function TicketPriceController() {
        var self = this;
        
      self.coursesKrk = ko.observableArray();
      self.coursesKat = ko.observableArray();
     
        self.viewCourses0 = ko.observable(false);
        self.viewCourses1 = ko.observable(false);
        
        self.show = ko.observable(false);
        self.message = ko.observable("ble"); 
        
        self.countPrice = function() {
            app.request++;
                       
            KKBus.Ajax.doGet('rest/busstops', function(data, textStatus, jqXHR) {
                var jsData = JSON.parse(data);
                              
                 if($('#formKierunekk').val() == 0){
                      
                    list1 = $('#formPrzystanekkrk').val();
                    
                    list2 = $('#formPrzystanekkat').val();
                    zm = jsData[list1].distance;
                    zm2 = jsData[list2].distance;
                    
                    
                    
                    if($('#formUlga').val() == 1){
                     
                     cena_biletu = (zm2-zm)*0.50*0.3;
                     self.show(true);  
                     self.message("Cena twojego biletu wynosi" + " " + cena_biletu + " " + "zł");
                     setTimeout(function() { self.show(false); }, 5000);
                     console.log(cena_biletu);
                     
                     
                    }else {
                        cena_biletu = (zm2-zm)*0.50;
                        self.show(true);  
                        self.message("Cena twojego biletu wynosi" + " " + cena_biletu + " " + "zł");
                        setTimeout(function() { self.show(false); }, 5000);
                        console.log("Cena" + "" + cena_biletu);
                        
                    }
                  }
                
                
                  else
                      
                      {
                    list3 = $('#formPrzystanekkrkk').val();
                    list4 = $('#formPrzystanekkatt').val();
                    zm3 = jsData[list3].distance;
                    zm4 = jsData[list4].distance;
                    
                    
                    
                    if($('#formUlga').val() == 1){
                     
                     cena_biletu = (zm3-zm4)*0.50*0.3;
                     self.show(true);  
                     self.message("Cena twojego biletu wynosi" + " " + cena_biletu + " " + "zł");
                     setTimeout(function() { self.show(false); }, 5000);
                     console.log(cena_biletu);
                     
                     
                    }else {
                        cena_biletu = (zm3-zm4)*0.50;
                        self.show(true);  
                        self.message("Cena twojego biletu wynosi" + " " + cena_biletu + " " + "zł");
                        setTimeout(function() { self.show(false); }, 5000);
                        console.log("Cena" + " " + cena_biletu);
                        
                    }
                      
                            
                      }
                     app.request--;     
                                  

            });
        };
        
        
        self.showCourses = function() {
            
            if($('#formKierunekk').val() == 0){
                self.viewCourses0(true);
                self.viewCourses1(false);
          

                
            } else {
               
                self.viewCourses1(true);
                self.viewCourses0(false);
              
                              
             
            }
            
            
        };
        
        
    }

    KKBus.TicketPriceController = TicketPriceController;
    
}(window.KKBus));